package
{
   import _effx.CigaretteSmoke_1;
   
   import _debug.Stats;
   
   import com.bit101.components.PushButton;
   
   import flash.display.Bitmap;
   import flash.display.MovieClip;
   import flash.display.StageAlign;
   import flash.display.StageScaleMode;
   import flash.events.Event;
   import flash.events.MouseEvent;
   
   public class CigaretteSmoke_1_Main extends MovieClip
   {
      // fla
      public var btn1:PushButton;
      public var btn2:PushButton;
      public var btn3:PushButton;
      public var btn4:PushButton;
      
      // particle
      private var part:CigaretteSmoke_1 = new CigaretteSmoke_1();
      
      // noise
      private var nozBmp:Bitmap;
      
      public function CigaretteSmoke_1_Main()
      {
         super();
         
         addEventListener(Event.ADDED_TO_STAGE, onAdd);
         addEventListener(Event.REMOVED_FROM_STAGE, onRemove);
      }
      
      // --------------------- LINE ---------------------
      
      // ################### protected ##################
      
      // #################### private ###################
      
      private function onAdd(e:Event):void
      {
         stage.scaleMode = StageScaleMode.NO_SCALE;
         stage.align = StageAlign.TOP_LEFT;
         
         addChildAt(part, 1);
         part.x = 0;
         part.y = 0;
         part.applyFilter();
         part.start();
         
         btn1 = new PushButton(this, 12, 46, 'play', 
            function(e:MouseEvent)
            {
               part.start();
            }
         );
         btn1.setSize(80, 35);
         
         btn2 = new PushButton(this, 12, 88, 'pause', 
            function(e:MouseEvent)
            {
               part.pause();
            }
         );
         btn2.setSize(80, 35);
         
         btn3 = new PushButton(this, 12, 130, 'stop', 
            function(e:MouseEvent)
            {
               part.stop();
            }
         );
         btn3.setSize(80, 35);
         
         btn4 = new PushButton(this, 12, 192, 'toggle filter', 
            function(e:MouseEvent)
            {
               if (nozBmp.bitmapData)
               {
                  nozBmp.bitmapData = null;
                  part.removeFilter();
               }
               else
               {
                  nozBmp.bitmapData = part.nozBmpd;
                  part.applyFilter();
               }
            }
         );
         btn4.setSize(80, 35);
         btn4.toggle = true;
         btn4.selected = true;
         
         // --- noise ---
         nozBmp = new Bitmap();
         nozBmp.x = 11;
         nozBmp.y = 234;
         nozBmp.bitmapData = part.nozBmpd;
         nozBmp.scaleX = 0.25;
         nozBmp.scaleY = 0.25;
         addChild(nozBmp);
         
         // benchmark
         var st:Stats = new Stats();
         st.x = 430;
         st.y = 0;
         addChild(st);
      }
      
      private function onRemove(e:Event):void
      {
      }
      
      // --------------------- LINE ---------------------
      
   }
   
}